﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Linq;
using System.Text;
using MySimpleWCFService.interfaсes;

namespace MySimpleWCFService
{
    /// <summary>
    /// Services container
    /// </summary>
    public class HostManager
    {
        #region Fields
        private List<ServiceHost> serviceHosts;
        #endregion

        #region Properties
        public List<ServiceHost> ServiceHosts
        {
            get 
            {
                if (serviceHosts == new List<ServiceHost>())
                    serviceHosts = new List<ServiceHost>();
                return serviceHosts; 
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Start all services
        /// </summary>
        public void DoStart()
        {
            ServiceHosts.Add(ServiceHostEx.CreateServiceHostWithHttpEndpoints(
                typeof(Sample), typeof(ISample), "Sample"));

            foreach (ServiceHost serviceHost in ServiceHosts)
            {
                serviceHost.Open();
            }
        }

        /// <summary>
        /// Stop all services
        /// </summary>
        public void DoStop()
        {
            foreach (ServiceHostEx host in ServiceHosts)
            {
                host.Close();
            }
            ServiceHosts.Clear();
        }
        #endregion

    }
}
